﻿using System;
using System.Collections.Generic;
using Ext.Net;
using BLL;
using Model;
using System.Xml;
using System.Xml.Xsl;

namespace Web.View.d50_mzxxMenu
{
    public partial class Default : UIPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        //绑定Grid
        protected void d50_mzxx_DataBind(object sender, StoreRefreshDataEventArgs e)
        {
            d50_mzxxMgr mgr = new d50_mzxxMgr();
            e.Total = int.Parse(mgr.GetRecordCount_d50_mzxx(e.Parameters[d50_mzxx_Filter.ParamPrefix]));
            IList<d50_mzxx> list = mgr.FindAllByPage_d50_mzxx(e.Start.ToString(), e.Limit.ToString(), e.Parameters[d50_mzxx_Filter.ParamPrefix]);
            d50_mzxx_MainStore.DataSource = list;
            d50_mzxx_MainStore.DataBind();
        }
        //删除数据
        protected void BtnDel_Click(object sender, DirectEventArgs e)
        {
            d50_mzxxMgr mgr = new d50_mzxxMgr();
            RowSelectionModel sm = d50_mzxx_Grid.SelectionModel.Primary as RowSelectionModel;
            foreach (SelectedRow row in sm.SelectedRows)
            {
                d50_mzxx _d50_mzxx = new d50_mzxx();
                _d50_mzxx.zyid = row.RecordID;//int.Parse(row.RecordID);
                if (mgr.Del_d50_mzxx(_d50_mzxx))
                {
                    log.Debug("d50_mzxx中执行了删除，并成功");
                    X.Msg.Notify("成功", "<font color='green'>已经成功删除选中的记录</font>").Show();
                }
                else
                    X.Msg.Notify("失败", "<font color='green'>删除记录失败，请您重试！</font>").Show();
            }
            d50_mzxx_Grid.Reload();
        }
        protected void BtnSave_Click(object sender, DirectEventArgs e)
        {
            d50_mzxxMgr mgr = new d50_mzxxMgr();
            d50_mzxx _d50_mzxx = new d50_mzxx();
            if (Hid.Text.Length > 0)
                _d50_mzxx = mgr.FindById_d50_mzxx(int.Parse(Hid.Text));
            
			_d50_mzxx.zybh = Txtzybh.Text.Trim();
			_d50_mzxx.mzbh = Txtmzbh.Text.Trim();
			_d50_mzxx.zycs = int.Parse(TxtNumzycs.Text.Trim());
			_d50_mzxx.dqbm = Txtdqbm.Text.Trim();
			_d50_mzxx.hbh = Txthbh.Text.Trim();
			_d50_mzxx.grbm = Txtgrbm.Text.Trim();
			_d50_mzxx.grade = Txtgrade.Text.Trim();
			_d50_mzxx.rbh = Txtrbh.Text.Trim();
			_d50_mzxx.dzbm = Txtdzbm.Text.Trim();
			_d50_mzxx.zbh = Txtzbh.Text.Trim();
			_d50_mzxx.cbh = Txtcbh.Text.Trim();
			_d50_mzxx.zen = Txtzen.Text.Trim();
			_d50_mzxx.cun = Txtcun.Text.Trim();
			_d50_mzxx.gldm = Txtgldm.Text.Trim();
			_d50_mzxx.jgdm = Txtjgdm.Text.Trim();
			_d50_mzxx.jgmc = Txtjgmc.Text.Trim();
			_d50_mzxx.usid = Txtusid.Text.Trim();
			_d50_mzxx.brlxid = Txtbrlxid.Text.Trim();
			_d50_mzxx.gfbh = Txtgfbh.Text.Trim();
			_d50_mzxx.brxm = Txtbrxm.Text.Trim();
			_d50_mzxx.xbid = Txtxbid.Text.Trim();
			_d50_mzxx.brnl = Txtbrnl.Text.Trim();
			_d50_mzxx.hzgx = Txthzgx.Text.Trim();
			_d50_mzxx.csrq = Txtcsrq.Text.Trim();
			_d50_mzxx.yebz = Txtyebz.Text.Trim();
			_d50_mzxx.hyzkmc = Txthyzkmc.Text.Trim();
			_d50_mzxx.hyid = Txthyid.Text.Trim();
			_d50_mzxx.csddmc = Txtcsddmc.Text.Trim();
			_d50_mzxx.mzmc = Txtmzmc.Text.Trim();
			_d50_mzxx.gjid = Txtgjid.Text.Trim();
			_d50_mzxx.sfzh = Txtsfzh.Text.Trim();
			_d50_mzxx.gzdw = Txtgzdw.Text.Trim();
			_d50_mzxx.dwdh = Txtdwdh.Text.Trim();
			_d50_mzxx.dwyb = Txtdwyb.Text.Trim();
			_d50_mzxx.hkdz = Txthkdz.Text.Trim();
			_d50_mzxx.hkyb = Txthkyb.Text.Trim();
			_d50_mzxx.lxrm = Txtlxrm.Text.Trim();
			_d50_mzxx.gxid = Txtgxid.Text.Trim();
			_d50_mzxx.lxdz = Txtlxdz.Text.Trim();
			_d50_mzxx.lxdh = Txtlxdh.Text.Trim();
			_d50_mzxx.ryksid = Txtryksid.Text.Trim();
			_d50_mzxx.ryksmc = Txtryksmc.Text.Trim();
			_d50_mzxx.rybs = Txtrybs.Text.Trim();
			_d50_mzxx.rycw = Txtrycw.Text.Trim();
			_d50_mzxx.rysj = Txtrysj.Text.Trim();
			_d50_mzxx.rybqid = Txtrybqid.Text.Trim();
			_d50_mzxx.zkbqid = Txtzkbqid.Text.Trim();
			_d50_mzxx.cyksid = Txtcyksid.Text.Trim();
			_d50_mzxx.cyksmc = Txtcyksmc.Text.Trim();
			_d50_mzxx.cybs = Txtcybs.Text.Trim();
			_d50_mzxx.cycw = Txtcycw.Text.Trim();
			_d50_mzxx.cysj = Txtcysj.Text.Trim();
			_d50_mzxx.zyts = int.Parse(TxtNumzyts.Text.Trim());
			_d50_mzxx.mzzd = Txtmzzd.Text.Trim();
			_d50_mzxx.ryzd = Txtryzd.Text.Trim();
			_d50_mzxx.zdmc = Txtzdmc.Text.Trim();
			_d50_mzxx.ryqzsj = Txtryqzsj.Text.Trim();
			_d50_mzxx.zyzt = Txtzyzt.Text.Trim();
			_d50_mzxx.yzxs = Txtyzxs.Text.Trim();
			_d50_mzxx.yzzj = Txtyzzj.Text.Trim();
			_d50_mzxx.qfje = Txtqfje.Text.Trim();
			_d50_mzxx.fdje = Txtfdje.Text.Trim();
			_d50_mzxx.bsbl = Txtbsbl.Text.Trim();
			_d50_mzxx.hjje = Txthjje.Text.Trim();
			_d50_mzxx.kbje = Txtkbje.Text.Trim();
			_d50_mzxx.mxhj = Txtmxhj.Text.Trim();
			_d50_mzxx.etys = Txtetys.Text.Trim();
			_d50_mzxx.mzys = Txtmzys.Text.Trim();
			_d50_mzxx.hlzt = Txthlzt.Text.Trim();
			_d50_mzxx.cwbz = Txtcwbz.Text.Trim();
			_d50_mzxx.qfjsbz = Txtqfjsbz.Text.Trim();
			_d50_mzxx.qfjsje1 = Txtqfjsje1.Text.Trim();
			_d50_mzxx.qfjsje = Txtqfjsje.Text.Trim();
			_d50_mzxx.jssj = Txtjssj.Text.Trim();
			_d50_mzxx.lsh = Txtlsh.Text.Trim();
			_d50_mzxx.hsx = Txthsx.Text.Trim();
			_d50_mzxx.chsx = Txtchsx.Text.Trim();

            bool isok = false;
            if (Hid.Text.Length > 0)
                isok = mgr.Update_d50_mzxx(_d50_mzxx);
            else
                isok = mgr.Add_d50_mzxx(_d50_mzxx);
            if (isok)
            {
                d50_mzxx_Win.Hide();
                X.Msg.Notify("成功", "<font color='green'>恭喜您，操作成功！</font>").Show();
                log.Debug("d50_mzxx中执行了保存（插入或修改），并成功");
                d50_mzxx_Grid.Reload();
            }
            else
                X.Msg.Notify("失败", "<font color='red'>操作失败，请您重试！</font>").Show();
        }
        //数据保存为Excel
        protected void BtnSaveToExcel(object sender, EventArgs e)
        {
            string json = ExcelGridData.Value.ToString();
            StoreSubmitDataEventArgs eSubmit = new StoreSubmitDataEventArgs(json, null);
            XmlNode xml = eSubmit.Xml;
            this.Response.Clear();
            this.Response.ContentType = "application/vnd.ms-excel";
            this.Response.AddHeader("Content-Disposition", "attachment; filename=QiDian10Excel.xls");
            XslCompiledTransform xtExcel = new XslCompiledTransform();
            xtExcel.Load(Server.MapPath("/View/ExcelTemp/Excel.xsl"));
            xtExcel.Transform(xml, null, this.Response.OutputStream);
            this.Response.End();

        }
    }
}